package com.example.administrator.liveapp.activity;

import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.support.transition.Visibility;
import android.support.v4.app.ActivityCompat;
import android.support.v4.view.ViewPager;
import android.support.v4.view.animation.LinearOutSlowInInterpolator;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.LinearInterpolator;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.administrator.liveapp.ApplicationUtils;
import com.example.administrator.liveapp.R;
import com.example.administrator.liveapp.Xutils3.MyCallBack;
import com.example.administrator.liveapp.Xutils3.XUtils;
import com.example.administrator.liveapp.base.BaseRVAdapter;
import com.example.administrator.liveapp.base.BaseViewHolder;
import com.example.administrator.liveapp.bean.MallDetailsPageBean;
import com.example.administrator.liveapp.utils.AppUrl;
import com.example.administrator.liveapp.utils.GlideImageLoader;
import com.example.administrator.liveapp.utils.NumberAddSubView;
import com.example.administrator.liveapp.utils.TimeChangeUtil;
import com.example.administrator.liveapp.view.FullyLinearLayoutManager;
import com.example.administrator.liveapp.view.StatusbarUtils;
import com.google.gson.Gson;
import com.tencent.mm.opensdk.modelpay.PayReq;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 商品详情activity
 */

public class MallDetailsPage extends AppCompatActivity implements View.OnClickListener {

    private Banner banner;
    private ImageView title_book_name;//商品名称
    private TextView book_name;//<商品名称>
    private TextView book_price;//商品价格
    private TextView open_booking;//销售状态
    private TextView send_time;//预售时间
    private TextView freight;//快递费
    private TextView sales_count;//销量
    private TextView brief;//商品简介
    private TextView content;//商品描述
    private MallDetailsPageBean bean;//实体类
    private TextView radioButton;//客服电话或留言
    private TextView mall_details_money;//加入购物车
    private TextView buy_now;//立即购买
    private ImageView share;
    private LinearLayout layout_bottom;
    private NestedScrollView scroll;
    private RelativeLayout mHeaderContent;
    private String bookId, bookPrice, remainCount;//商品id
    private RecyclerView questions;//商品留言列表
    private RelativeLayout comment;//咨询内容显示
    private TextView comment_null;//没有咨询提示
    private TextView write_note;//写留言
    private TextView book_price2;//商品原价
    private RelativeLayout relative_price;


    private View loadView;//loding页面（加载页）
    private WebView webView;
    //弹窗
    private PopupWindow mPopWindow;
    private Button confirm_button;//确认提交
    private LinearLayout booking_layout;
    private NumberAddSubView number;//商品数量
    private ImageView shopping_book_image;//商品图片
    private TextView shopping_book_money;//商品单价
    private TextView shopping_stock;//库存

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ApplicationUtils applicationUtils = new ApplicationUtils();
        applicationUtils.addActivity(this);
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("action.refreshFriend");
        registerReceiver(mRefreshBroadcastReceiver, intentFilter);
        initView();
        collection();
    }

    private BroadcastReceiver mRefreshBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals("action.refreshFriend")) {
                collection();
            }
        }
    };

    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(mRefreshBroadcastReceiver);
    }

    private void initView() {
        //        if (Build.VERSION.SDK_INT >= 23) {
//            String[] mPermissionList = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.CALL_PHONE, Manifest.permission.READ_LOGS, Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.SET_DEBUG_APP, Manifest.permission.SYSTEM_ALERT_WINDOW, Manifest.permission.GET_ACCOUNTS, Manifest.permission.WRITE_APN_SETTINGS};
//            ActivityCompat.requestPermissions(this, mPermissionList, 123);
//        }
        //去掉Activity上面的状态栏
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        //设置透明状态栏
//        StatusbarUtils.enableTranslucentStatusbar(this);
        setContentView(R.layout.activity_mall_details_page);
        loadView = findViewById(R.id.loadViews);
        share = (ImageView) findViewById(R.id.share);
        radioButton = (TextView) findViewById(R.id.radioButton);
        mall_details_money = (TextView) findViewById(R.id.mall_details_money);
        buy_now = (TextView) findViewById(R.id.buy_now);
        banner = (Banner) findViewById(R.id.banner);
        title_book_name = (ImageView) findViewById(R.id.title_book_name);
        book_name = (TextView) findViewById(R.id.book_name);
        book_price = (TextView) findViewById(R.id.book_price);
        open_booking = (TextView) findViewById(R.id.open_booking);
        send_time = (TextView) findViewById(R.id.send_time);
        sales_count = (TextView) findViewById(R.id.sales_count);
        book_price2 = (TextView) findViewById(R.id.book_price2);
        relative_price = (RelativeLayout) findViewById(R.id.relative_price);
        freight = (TextView) findViewById(R.id.freight);
//        brief = (TextView) findViewById(R.id.brief);
        content = (TextView) findViewById(R.id.content);
        layout_bottom = (LinearLayout) findViewById(R.id.layout_bottom);
        mHeaderContent = (RelativeLayout) findViewById(R.id.ll_header_content);
        scroll = (NestedScrollView) findViewById(R.id.scroll);
        webView = (WebView) findViewById(R.id.webView);
        questions = (RecyclerView) findViewById(R.id.questions);
        comment_null = (TextView) findViewById(R.id.comment_null);
        comment = (RelativeLayout) findViewById(R.id.comment);
        write_note = (TextView) findViewById(R.id.write_note);
        write_note.setOnClickListener(this);
        title_book_name.setOnClickListener(this);
        share.setOnClickListener(this);
        mall_details_money.setOnClickListener(this);
        radioButton.setOnClickListener(this);
        buy_now.setOnClickListener(this);
        comment.setOnClickListener(this);
        findViewById(R.id.shopping_image).setOnClickListener(this);
        banner.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, this.getWindowManager().getDefaultDisplay().getWidth() / 1 * 1));
    }

    String[] image;
    List<String> images;
    private void collection() {
        Intent intent = getIntent();
        bookId = intent.getStringExtra("bookId");
        bookPrice = intent.getStringExtra("bookPrice");
        remainCount = intent.getStringExtra("remainCount");
        String url = AppUrl.URL + AppUrl.ShoppingDetailsUrl;
        Map<String, String> map = new HashMap<>();
        map.put("bookId", bookId);
        XUtils.Get(url, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                Gson gson = new Gson();
                images = new ArrayList<String>();
                bean = gson.fromJson(result, MallDetailsPageBean.class);
                if(bean.getBook().getBookimgurl()!=null){
                    image = bean.getBook().getBookimgurl().split("\\|");
                    for (int i=0;i<image.length;i++){
                        images.add(i,AppUrl.URL+image[i]);
                        Log.e("dd",images.get(i).toString());
                    }
                }
                book_name.setText(bean.getBook().getBooktitle());
                book_price.setText("¥" + bookPrice);
                if(bean.getBook().getDiscount().equals("1")){
                    relative_price.setVisibility(View.GONE);
                }else{
                    relative_price.setVisibility(View.VISIBLE);
                    book_price2.setText("¥"+bean.getBook().getBookprice());
                }
                if (bean.getBook().getSalesdate().equals("1")) {
                    open_booking.setText("在售");
                    open_booking.setVisibility(View.GONE);
                    send_time.setVisibility(View.GONE);
                } else if (bean.getBook().getSalesdate().equals("2")) {
                    open_booking.setVisibility(View.VISIBLE);
                    send_time.setVisibility(View.VISIBLE);
                    open_booking.setText("预售");
                    send_time.setText("发货日期: " + TimeChangeUtil.getStrTime2(bean.getBook().getBooktime()));
                } else if (bean.getBook().getSalesdate().equals("3")) {
                    open_booking.setVisibility(View.VISIBLE);
                    send_time.setVisibility(View.VISIBLE);
                    open_booking.setText("众筹");
                    send_time.setText("结束日期: " + TimeChangeUtil.getStrTime2(bean.getBook().getBooktime()));
                }
                if (bean.getBook().getFreight().equals("0.00")) {
                    freight.setText("包邮");
                } else {
                    freight.setText("邮费:" + bean.getBook().getFreight());
                }
                sales_count.setText("已售:" + bean.getBook().getSalescount());
//                brief.setText(bean.getBook().getBrief());
                content.setText(bean.getBook().getContent());
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
            }

            @Override
            public void onFinished() {
                super.onFinished();
                LoadWebView();
                banner();
//                loadView.setVisibility(View.GONE);
                if (bean.getBookreply() == null) {
                    comment.setVisibility(View.GONE);
                    comment_null.setVisibility(View.VISIBLE);
                    return;
                }
                FullyLinearLayoutManager linearLayoutManager = new FullyLinearLayoutManager(MallDetailsPage.this);
                linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                questions.setLayoutManager(linearLayoutManager);
                questions.setHasFixedSize(true);
                questions.setNestedScrollingEnabled(false);
                BaseRVAdapter adapter = new BaseRVAdapter(MallDetailsPage.this, bean.getBookreply()) {
                    @Override
                    public int getLayoutId(int viewType) {
                        return R.layout.questions_layout;
                    }

                    @Override
                    public int getItemCount() {
                        if (bean.getBookreply() != null) {
                            if (bean.getBookreply().size() >= 4) {
                                return 4;
                            }
                            return bean.getBookreply().size();
                        }
                        return 0;
                    }

                    @Override
                    public void onBind(BaseViewHolder holder, int position) {

                        if (bean.getBookreply().get(position).getReplycomment() != null) {
                            comment_null.setVisibility(View.GONE);
                            comment.setVisibility(View.VISIBLE);
                            holder.setTextView(R.id.questions_text, bean.getBookreply().get(position).getReplycomment());
                            holder.setTextView(R.id.questions_time, TimeChangeUtil.getStrTime4(bean.getBookreply().get(position).getReplytime()));
                        }
                        addItemClickListener(new OnItemClickListener() {
                            @Override
                            public void itemSelect(int position) {
                                startActivity(new Intent(MallDetailsPage.this, Answering.class).putExtra("bookId", bean.getBook().getBookid()));
                            }
                        });
                    }

                };
                questions.setAdapter(adapter);
            }
        });
    }

    /**
     * 顶部ViewPager样式设置
     */

    public void banner() {
        //设置banner样式
        banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
        //设置图片加载器
        banner.setImageLoader(new GlideImageLoader());
        //设置图片集合
        banner.setImages(images);
        //设置banner动画效果
        banner.setBannerAnimation(Transformer.Default);
        //设置标题集合（当banner样式有显示title时）
//        banner.setBannerTitles(titles);
        //设置自动轮播，默认为true
        banner.isAutoPlay(true);
        //设置轮播时间
        banner.setDelayTime(5000);
        //设置指示器位置（当banner模式中有指示器时）
        banner.setIndicatorGravity(BannerConfig.CENTER);
        //banner设置方法全部调用完毕时最后调用
        banner.start();
        //解决banner(ViewPage)和swipeRefreshLayout(下拉刷新的冲突事件)
        banner.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(int position) {
            }

            @Override
            public void onPageScrollStateChanged(int state) {
//                enableDisableSwipeRefresh(state == ViewPager.SCROLL_STATE_IDLE);
            }

        });
    }

    @Override
    public void onStart() {
        super.onStart();
        //开始轮播
        banner.startAutoPlay();
    }

    @Override
    public void onStop() {
        super.onStop();
        //结束轮播
        banner.stopAutoPlay();
    }

    String webUrl;

    private void LoadWebView() {
        // 开启 localStorage
        webView.getSettings().setDomStorageEnabled(true);
        // 设置支持javascript
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setDefaultTextEncodingName("utf-8");
        // 启动缓存
        webView.getSettings().setAppCacheEnabled(true);
        // 设置缓存模式
        webView.requestFocus();
        webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
        //设置响应js 的Alert()函数
        webView.setWebChromeClient(new WebChromeClient());
        webUrl = AppUrl.URL + "index.php/ban/index/book_info_mobile.html?id=" + bookId;//type是为了区分APP传参和web页面传参
        webView.loadUrl(webUrl);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                loadView.setVisibility(View.GONE);
            }

            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
            }
        });
    }

    private void showPopupWindow() {
        //设置contentView
        View contentView = LayoutInflater.from(MallDetailsPage.this).inflate(R.layout.malldetails_popwindow, null);
        mPopWindow = new PopupWindow(contentView,
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, true);
        mPopWindow.setContentView(contentView);
        confirm_button = (Button) contentView.findViewById(R.id.confirm_button);
        shopping_book_image = (ImageView) contentView.findViewById(R.id.shopping_book_image);
        shopping_book_money = (TextView) contentView.findViewById(R.id.shopping_book_money);
        shopping_stock = (TextView) contentView.findViewById(R.id.shopping_stock);
        number = (NumberAddSubView) contentView.findViewById(R.id.number);
        String Url = bean.getBook().getBookimgurl();
        String ImageUrl = Url.substring(1, Url.indexOf("|"));
        Glide.with(MallDetailsPage.this)
                .load(AppUrl.URL + ImageUrl)
                .into(shopping_book_image);
        shopping_book_money.setText("¥ " + bookPrice);
        shopping_stock.setText("库存:" + remainCount);
        number.setValue(1);
        number.setMaxValue(Integer.parseInt(remainCount));
        //设置各个控件的点击响应
        contentView.findViewById(R.id.popw_close).setOnClickListener(this);
        confirm_button.setOnClickListener(this);
        //显示PopupWindow
        View rootview = LayoutInflater.from(MallDetailsPage.this).inflate(R.layout.activity_mall_details_page, null);
        showPopmenu(rootview);
    }

    private void showPopmenu(View rootview) {
        mPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp = getWindow().getAttributes();
                lp.alpha = 1f;
                getWindow().setAttributes(lp);
            }
        });
        // 显示窗口位置
        mPopWindow.showAtLocation(rootview, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        // 设置layout在PopupWindow中显示的位置
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.alpha = 0.4f;
        getWindow().setAttributes(lp);
    }

    /**
     * 调用拨号界面
     *
     * @param tel 电话号码
     */
    private void call(String tel) {
        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + tel));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
    }

    int position = 0;
    int judgment;
    java.text.DecimalFormat df = new java.text.DecimalFormat("0.00");//精确到小数点后两位

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.write_note:
                if (ApplicationUtils.getInstance().loginBean != null) {
                    startActivity(new Intent(this, ShoppingMessage.class).putExtra("bookId", bean.getBook().getBookid()));
                } else {
                    startActivity(new Intent(this,WxLoginPage.class));
                    overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
                    Toast.makeText(this, "用户未登录，请登录后留言", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.shopping_image:
                if (ApplicationUtils.getInstance().loginBean == null) {
                    Toast.makeText(MallDetailsPage.this, "亲,你还没有登录!", Toast.LENGTH_SHORT).show();
                } else if (ApplicationUtils.getInstance().loginBean.getConsumertel() == null && ApplicationUtils.getInstance().loginBean != null) {
                    Toast.makeText(MallDetailsPage.this, "请先绑定手机号", Toast.LENGTH_SHORT).show();
                    Intent intent1 = new Intent(MallDetailsPage.this, BindingPhonePage.class);
                    startActivity(intent1);
                    overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
                } else {
                    Intent intent = new Intent();
                    intent.setClass(this, ShoppingCart.class);
                    startActivity(intent);
                    overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
                }
                break;
            case R.id.popw_close:
                if (mPopWindow != null && mPopWindow.isShowing()) {
                    mPopWindow.dismiss();
                }
                break;
            case R.id.confirm_button://确认提交
                if (mPopWindow != null && mPopWindow.isShowing()) {
                    mPopWindow.dismiss();
                }
                if (judgment == 1) {
                    double sum = (Double.parseDouble(bean.getBook().getBookprice()) * Double.parseDouble(bean.getBook().getDiscount())) * number.getValue();
                    double freights = Double.parseDouble(bean.getBook().getFreight());
                    Intent intent = new Intent(MallDetailsPage.this, CommodityPayActivity.class);
                    intent.putExtra("sum", df.format(sum + freights));
                    intent.putExtra("freights", df.format(freights));
                    intent.putExtra("bookId", bean.getBook().getBookid());
                    intent.putExtra("bookNum", number.getValue() + "");
                    intent.putExtra("status", "0");
                    startActivity(intent);
                    overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
                } else if (judgment == 2) {
                    String url = AppUrl.URL + AppUrl.AddCartURL;
                    Map<String, String> map = new HashMap<>();
                    if (ApplicationUtils.getInstance().loginBean != null) {
                        map.put("consumerId", ApplicationUtils.getInstance().loginBean.getConsumerid());
                    }
                    map.put("bookId", bean.getBook().getBookid());
                    map.put("bookNum", number.getValue() + "");
                    XUtils.Get(url, map, new MyCallBack<String>() {
                        @Override
                        public void onSuccess(String result) {
                            super.onSuccess(result);
                            JSONObject jsonObject = null;
                            try {
                                jsonObject = new JSONObject(result);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            String results = jsonObject.optString("result");
                            if (results.equals("true")) {
                                Toast.makeText(MallDetailsPage.this, "已加入购物车", Toast.LENGTH_SHORT).show();
                            }
                        }

                        @Override
                        public void onError(Throwable ex, boolean isOnCallback) {
                            super.onError(ex, isOnCallback);
                        }

                        @Override
                        public void onFinished() {
                            super.onFinished();
                        }
                    });
                }

                break;
            case R.id.buy_now://立即购买
                if (ApplicationUtils.getInstance().loginBean == null) {
                    Toast.makeText(MallDetailsPage.this, "亲,你还没有登录!", Toast.LENGTH_SHORT).show();
                } else if (ApplicationUtils.getInstance().loginBean.getConsumertel() == null && ApplicationUtils.getInstance().loginBean != null) {
                    Toast.makeText(MallDetailsPage.this, "请先绑定手机号", Toast.LENGTH_SHORT).show();
                    Intent intent1 = new Intent(MallDetailsPage.this, BindingPhonePage.class);
                    startActivity(intent1);
                    overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
                } else if(remainCount.equals("0")){
                    Toast.makeText(MallDetailsPage.this, "亲,该商品库存不足!", Toast.LENGTH_SHORT).show();
                }else {
                    showPopupWindow();
                    judgment = 1;
                }
                break;
            case R.id.mall_details_money://加入购物车
                if (ApplicationUtils.getInstance().loginBean == null) {
                    Toast.makeText(MallDetailsPage.this, "亲,你还没有登录!", Toast.LENGTH_SHORT).show();
                } else if (ApplicationUtils.getInstance().loginBean.getConsumertel() == null && ApplicationUtils.getInstance().loginBean != null) {
                    Toast.makeText(MallDetailsPage.this, "请先绑定手机号", Toast.LENGTH_SHORT).show();
                    Intent intent1 = new Intent(MallDetailsPage.this, BindingPhonePage.class);
                    startActivity(intent1);
                    overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
                }else if(remainCount.equals("0")){
                    Toast.makeText(MallDetailsPage.this, "亲,该商品库存不足!", Toast.LENGTH_SHORT).show();
                } else {
                    showPopupWindow();
                    judgment = 2;
                }
                break;
            case R.id.title_book_name:
                finish();
                break;
            case R.id.radioButton://客服
                call(bean.getBook().getStoretel());
                break;
            case R.id.share:
                String Url = bean.getBook().getBookimgurl();
                String ImageUrl = Url.substring(1, Url.indexOf("|"));
                UMImage image = new UMImage(MallDetailsPage.this, AppUrl.URL + ImageUrl);//资源文件
                UMImage thumb = new UMImage(this, AppUrl.URL + ImageUrl);
                image.setThumb(thumb);
                UMWeb web = new UMWeb(AppUrl.URL + "index.php/ban/index/book_info.html?id=" + bookId);
                web.setTitle(bean.getBook().getBooktitle());//标题
                web.setThumb(thumb);  //缩略图
                web.setDescription(bean.getBook().getBrief());//描述
                //不带面板链接分享
//                new ShareAction(MallDetailsPage.this)
//                        .setPlatform(SHARE_MEDIA.WEIXIN)//传入平台
//                        .withText("hello")//分享内容
//                        .setCallback(shareListener)//回调监听器
//                        .share();

                //带面板文本分享
                new ShareAction(MallDetailsPage.this)
                        .withMedia(web)
                        .setDisplayList(SHARE_MEDIA.WEIXIN_CIRCLE,SHARE_MEDIA.WEIXIN ,SHARE_MEDIA.SINA, SHARE_MEDIA.QQ)
                        .setCallback(shareListener)
                        .open();


//                new ShareAction(MallDetailsPage.this)
//                        .withMedia(web)
//                        .setDisplayList(SHARE_MEDIA.SINA,SHARE_MEDIA.QQ,SHARE_MEDIA.WEIXIN)
//                        .setCallback(shareListener)
//                        .open();
                break;
        }
    }

    private UMShareListener shareListener = new UMShareListener() {
        /**
         * @descrption 分享开始的回调
         * @param platform 平台类型
         */
        @Override
        public void onStart(SHARE_MEDIA platform) {

        }

        /**
         * @descrption 分享成功的回调
         * @param platform 平台类型
         */
        @Override
        public void onResult(SHARE_MEDIA platform) {
            Toast.makeText(MallDetailsPage.this, "分享成功", Toast.LENGTH_LONG).show();
        }

        /**
         * @descrption 分享失败的回调
         * @param platform 平台类型
         * @param t 错误原因
         */
        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            Toast.makeText(MallDetailsPage.this, "分享失败" + t.getMessage(), Toast.LENGTH_LONG).show();
        }

        /**
         * @descrption 分享取消的回调
         * @param platform 平台类型
         */
        @Override
        public void onCancel(SHARE_MEDIA platform) {
            Toast.makeText(MallDetailsPage.this, "分享取消", Toast.LENGTH_LONG).show();

        }
    };

    /**
     * 分享是否同意的回调
     *
     * @param requestCode
     * @param permissions
     * @param grantResults
     */
    @Override
    public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {

    }

}
